<?php
/* this script outputs the profile image 
	of the requested user in the database */

// include the global config file
require_once("config.php");

// external lib: Opauth lib for authentication
require_once("lib/Opauth/Opauth.php");

// application internal classes
require_once("class/cache.class.php");
require_once("class/database.class.php");
require_once("class/blog.class.php");
require_once("class/user.class.php");
require_once("class/crypto.class.php");

// instanciate the blog
$b = new blog($_SERVER["HTTP_HOST"]);
if(array_key_exists("user", $_GET)){
	$userInfo = $b->db->getUser($_GET["user"]);
	$userImage = file_get_contents($userInfo["user_imageurl"]);

	// set the expires header to enforce caching
	header("Cache-Control: max-age=604800");
	header('Date: '.gmdate('D, d M Y H:i:s \G\M\T', time()));
	header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', time()));
	header("Expires: ".gmdate('D, d M Y H:i:s \G\M\T',(time()+604800)));
				
	// output the result image
	header("Content-Type: image/jpeg");
	print($userImage);
}
?>